//
//  MapDetailViewController.m
//  GoMap
//
//  Created by jsheriff on 2/11/11.
//  Copyright 2011 The MITRE Corporation. All rights reserved.
//

#import "MapDetailViewController.h"
#import "MapSelectionTableViewController.h"

@implementation MapDetailViewController

@synthesize mapPack;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	displayNameLabel.text = mapPack.displayName;
	thumbnailImageView.image = mapPack.thumbnailImage;
	descriptionLabel.text = mapPack.description;
	layersLabel.text = mapPack.layers;
	zoomLevelsLabel.text = [NSString stringWithFormat:@"%d to %d", mapPack.minZoom, mapPack.maxZoom];
	
	[deleteButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
}

-(IBAction)deleteMapPack:(id)sender {
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Map Pack" otherButtonTitles:nil];
	[actionSheet showInView:self.view];
	[actionSheet release];
}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
	if (!(buttonIndex == [actionSheet cancelButtonIndex])) {
		[[NSNotificationCenter defaultCenter] postNotificationName:kMapSelectionChanged object:self userInfo:nil];	
		
		NSFileManager *fileManager = [NSFileManager defaultManager];
		[fileManager removeItemAtPath:mapPack.fileName error:nil];
		
		[self.navigationController popViewControllerAnimated:YES]; 
	}
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
	[mapPack release];
    [super dealloc];
}


@end
